sources <- c("ESPN", "FantasyData", "FantasyPros", "FantasySharks", 
             "FantasyFootballNerd", "NumberFire", "Yahoo",
             "RTSports", "Walterfootball")

scrape <- scrape_data(src = sources,
                      pos = c('QB', 'RB', 'WR', 'TE', 'DST'),
                      season = 2020, 
                      week = week)

Simulation Time!

n_sims <- 10000

tic()
sim_lu <- map_df(1:n_sims, generate_lineup) %>%
  rename(pts_base = points) %>%  
  mutate(position = factor(position, 
                           levels = c("QB", "RB", "WR", "TE", "DST"))) %>% 
  select(lineup, Name, team, position, pts_base, pts_pred, sd_pts, Salary)
toc()
## 292.971 sec elapsed

Results

ggplotly(sim_lu %>% 
           group_by(Name, position, Salary) %>% 
           dplyr::summarize(lu = n_distinct(lineup)) %>% 
           ungroup() %>% 
           group_by(position) %>% 
           top_n(10, lu) %>% 
           ungroup() %>% 
           arrange(position, desc(lu)) %>% 
           mutate(Name = factor(Name),
                  Name = fct_reorder(Name, lu),
                  pct = round(lu / n_sims, 3) * 100) %>% 
           ggplot(aes(x = Name, y = pct, fill = Salary,
                      text = paste(Name, "in", lu, "lineups with", Salary, "salary"))) +
           geom_bar(stat = "identity") +
           facet_wrap(~position, ncol = 2, scales = "free_y") +
           coord_flip() +
           scale_fill_viridis_c() +
           xlab("") +
           ylab("Lineups (thousands)") +
           ggtitle("Top 10 Players By Position")) %>% 
  ggplotly(tooltip = "text")
plyr_lu <- sim_lu %>%
  group_by(Name, position) %>%
  dplyr::summarize(lu=n_distinct(lineup)) %>%
  ungroup() 

ggplotly(projections %>% 
  filter(avg_type=='weighted') %>%
  mutate(Name = ifelse(pos=="DST", last_name, paste(first_name, last_name))) %>%
  inner_join(fan_duel, by = c("Name", "position")) %>%
  select(Name, team, position, points, Salary, sd_pts) %>%
  left_join(plyr_lu, by='Name') %>%
  replace_na(list(lu=0)) %>%
  mutate(lu_bin=ifelse(lu==0, '0 Lineups', '>=1 Lineups'),
         lu_5=cut(lu,5, labels = FALSE)) %>%
  ggplot(aes(x=Salary, y=points, color=lu_bin, size=sd_pts, text=Name)) +
  geom_point() +
  theme_minimal() +
  scale_color_manual(values = c('red', 'blue'), name="") +
  geom_smooth(inherit.aes = FALSE, aes(x=Salary, y=points), method = 'lm') +
  ylab('Projected Points') +
  xlab('Salary') +
  ggtitle('Who makes it into Optimized Lineups?') +
  scale_x_continuous(labels=scales::dollar))
lu_df <- sim_lu %>%
  group_by(lineup) %>%
  dplyr::summarize(lineup_pts=sum(pts_pred),
                   lineup_sd=sum(sd_pts)) %>%
  ungroup()

pto <- psel(lu_df, low(lineup_sd) * high(lineup_pts))


ggplotly(ggplot(lu_df, aes(y=lineup_pts, x=lineup_sd, text = paste0("Lineup: ", lineup))) +
  geom_point() +
  geom_point(data=pto, size=5) +
  ylab('Lineup Points') +
  xlab('Lineup Points St Dev') +
  ggtitle('Lineup Points vs. Uncertainty',
          subtitle = 'Pareto Lineups Bolded'))
psel(lu_df, low(lineup_sd) * high(lineup_pts)) %>%
  left_join(sim_lu, by='lineup') %>%
  group_by(lineup) %>%
  arrange(lineup_pts, position, desc(Salary)) %>%
  select(lineup, lineup_pts, lineup_sd, Name, team, position, pts_pred, sd_pts, Salary) %>%
  mutate_at(vars(lineup_pts, lineup_sd, pts_pred, sd_pts), function(x) round(x, 2)) %>%
  knitr::kable() %>%
  kable_styling(fixed_thead = T) %>%
  column_spec(1:3, bold=TRUE) %>%
  collapse_rows(columns = 1:3, valign = 'top') %>%
  scroll_box(height = '700px', width = '100%')
lineup lineup_pts lineup_sd Name team position pts_pred sd_pts Salary
1456 127.94 3.91 Deshaun Watson HOU QB 22.55 0.50 8200
Alvin Kamara NOS RB 15.88 0.24 7500
Austin Ekeler LAC RB 16.51 0.20 7000
David Montgomery CHI RB 13.31 0.34 6200
Michael Thomas NOS WR 13.40 0.29 7200
Cooper Kupp LAR WR 12.89 0.52 6600
Jarvis Landry CLE WR 11.88 0.60 6000
Darren Waller LVR TE 13.52 0.84 7000
Green Bay Packers GBP DST 8.00 0.37 4100
6860 128.59 4.30 Russell Wilson SEA QB 24.34 0.78 9000
Dalvin Cook MIN RB 23.00 0.71 10500
Austin Ekeler LAC RB 16.34 0.20 7000
David Montgomery CHI RB 12.48 0.34 6200
Michael Thomas NOS WR 13.59 0.29 7200
Cooper Kupp LAR WR 13.66 0.52 6600
Keke Coutee HOU WR 8.94 0.46 4800
Anthony Firkser TEN TE 8.28 0.62 4600
Green Bay Packers GBP DST 7.95 0.37 4100
2112 128.80 4.37 Deshaun Watson HOU QB 22.07 0.50 8200
James Robinson JAC RB 18.30 0.87 7800
Alvin Kamara NOS RB 15.59 0.24 7500
Austin Ekeler LAC RB 15.84 0.20 7000
A.J. Brown TEN WR 15.58 0.44 8200
Cooper Kupp LAR WR 13.50 0.52 6600
Jarvis Landry CLE WR 11.59 0.60 6000
Anthony Firkser TEN TE 8.36 0.62 4600
Green Bay Packers GBP DST 7.96 0.37 4100
4514 129.67 4.45 Deshaun Watson HOU QB 22.24 0.50 8200
Alvin Kamara NOS RB 15.91 0.24 7500
Austin Ekeler LAC RB 15.98 0.20 7000
David Montgomery CHI RB 13.53 0.34 6200
DeVante Parker MIA WR 13.79 0.63 6800
Cooper Kupp LAR WR 12.96 0.52 6600
Brandin Cooks HOU WR 14.69 0.81 6500
Darren Waller LVR TE 12.49 0.84 7000
Green Bay Packers GBP DST 8.06 0.37 4100
5082 129.70 4.53 Deshaun Watson HOU QB 21.71 0.50 8200
Dalvin Cook MIN RB 23.35 0.71 10500
Alvin Kamara NOS RB 15.83 0.24 7500
Austin Ekeler LAC RB 16.16 0.20 7000
DeVante Parker MIA WR 13.85 0.63 6800
Brandin Cooks HOU WR 13.20 0.81 6500
Keke Coutee HOU WR 9.91 0.46 4800
Anthony Firkser TEN TE 7.63 0.62 4600
Green Bay Packers GBP DST 8.05 0.37 4100
2413 131.27 4.65 Deshaun Watson HOU QB 22.79 0.50 8200
James Robinson JAC RB 17.09 0.87 7800
Alvin Kamara NOS RB 15.90 0.24 7500
Austin Ekeler LAC RB 15.96 0.20 7000
Robert Woods LAR WR 15.05 0.70 7100
DeVante Parker MIA WR 14.10 0.63 6800
Cooper Kupp LAR WR 13.95 0.52 6600
Anthony Firkser TEN TE 8.27 0.62 4600
Green Bay Packers GBP DST 8.17 0.37 4100
9695 132.03 5.04 Deshaun Watson HOU QB 22.37 0.50 8200
James Robinson JAC RB 17.90 0.87 7800
Alvin Kamara NOS RB 15.75 0.24 7500
Austin Ekeler LAC RB 15.82 0.20 7000
Cooper Kupp LAR WR 13.64 0.52 6600
Brandin Cooks HOU WR 13.81 0.81 6500
Jarvis Landry CLE WR 12.07 0.60 6000
Darren Waller LVR TE 14.46 0.84 7000
New York Giants NYG DST 6.21 0.46 3400
3389 132.58 5.18 Deshaun Watson HOU QB 21.79 0.50 8200
James Robinson JAC RB 18.92 0.87 7800
Austin Ekeler LAC RB 16.06 0.20 7000
David Montgomery CHI RB 13.19 0.34 6200
Robert Woods LAR WR 15.14 0.70 7100
Cooper Kupp LAR WR 13.66 0.52 6600
Brandin Cooks HOU WR 13.85 0.81 6500
Darren Waller LVR TE 13.26 0.84 7000
Detroit Lions DET DST 6.71 0.40 3500
2650 133.32 5.64 Deshaun Watson HOU QB 21.94 0.50 8200
James Robinson JAC RB 17.76 0.87 7800
Austin Ekeler LAC RB 16.06 0.20 7000
David Montgomery CHI RB 13.46 0.34 6200
Robert Woods LAR WR 14.09 0.70 7100
Cooper Kupp LAR WR 12.94 0.52 6600
Brandin Cooks HOU WR 13.65 0.81 6500
Darren Waller LVR TE 15.39 0.84 7000
Atlanta Falcons ATL DST 8.02 0.86 3500
798 133.55 5.96 Deshaun Watson HOU QB 21.86 0.50 8200
Alvin Kamara NOS RB 16.00 0.24 7500
Austin Ekeler LAC RB 16.25 0.20 7000
Devontae Booker LVR RB 14.58 1.79 6000
Robert Woods LAR WR 15.42 0.70 7100
Cooper Kupp LAR WR 13.40 0.52 6600
Brandin Cooks HOU WR 14.21 0.81 6500
Darren Waller LVR TE 14.05 0.84 7000
Green Bay Packers GBP DST 7.78 0.37 4100
7706 133.73 6.11 Deshaun Watson HOU QB 22.50 0.50 8200
James Robinson JAC RB 19.67 0.87 7800
Austin Ekeler LAC RB 16.10 0.20 7000
Devontae Booker LVR RB 16.59 1.79 6000
DK Metcalf SEA WR 15.69 0.55 8500
Cooper Kupp LAR WR 12.49 0.52 6600
Keke Coutee HOU WR 9.41 0.46 4800
Darren Waller LVR TE 13.49 0.84 7000
Green Bay Packers GBP DST 7.80 0.37 4100
9120 135.99 6.22 Justin Herbert LAC QB 21.10 0.26 7900
Dalvin Cook MIN RB 22.66 0.71 10500
Austin Ekeler LAC RB 16.19 0.20 7000
David Montgomery CHI RB 13.44 0.34 6200
Robert Woods LAR WR 14.71 0.70 7100
Nelson Agholor LVR WR 17.34 2.33 5400
Keke Coutee HOU WR 9.11 0.46 4800
Darren Waller LVR TE 13.62 0.84 7000
Green Bay Packers GBP DST 7.83 0.37 4100
212 136.01 6.79 Deshaun Watson HOU QB 21.77 0.50 8200
James Robinson JAC RB 19.57 0.87 7800
Austin Ekeler LAC RB 16.13 0.20 7000
Devontae Booker LVR RB 17.66 1.79 6000
Robert Woods LAR WR 14.59 0.70 7100
DeVante Parker MIA WR 13.58 0.63 6800
Brandin Cooks HOU WR 13.47 0.81 6500
Darren Waller LVR TE 13.01 0.84 7000
New York Giants NYG DST 6.23 0.46 3400
3697 137.62 6.95 Deshaun Watson HOU QB 23.00 0.50 8200
Dalvin Cook MIN RB 22.12 0.71 10500
Austin Ekeler LAC RB 16.35 0.20 7000
Jamaal Williams GBP RB 17.98 2.57 5200
Robert Woods LAR WR 14.81 0.70 7100
Jarvis Landry CLE WR 12.04 0.60 6000
Keke Coutee HOU WR 9.14 0.46 4800
Darren Waller LVR TE 14.55 0.84 7000
Green Bay Packers GBP DST 7.63 0.37 4100
2801 137.70 7.06 Russell Wilson SEA QB 24.32 0.78 9000
Dalvin Cook MIN RB 24.06 0.71 10500
Austin Ekeler LAC RB 16.09 0.20 7000
David Montgomery CHI RB 13.47 0.34 6200
Robert Woods LAR WR 14.50 0.70 7100
Cooper Kupp LAR WR 13.09 0.52 6600
Nelson Agholor LVR WR 18.12 2.33 5400
Anthony Firkser TEN TE 7.26 0.62 4600
Atlanta Falcons ATL DST 6.78 0.86 3500
2628 143.20 7.35 Deshaun Watson HOU QB 22.30 0.50 8200
Derrick Henry TEN RB 25.11 1.77 10000
Alvin Kamara NOS RB 15.95 0.24 7500
Austin Ekeler LAC RB 16.32 0.20 7000
Cooper Kupp LAR WR 14.13 0.52 6600
Brandin Cooks HOU WR 13.51 0.81 6500
Nelson Agholor LVR WR 19.30 2.33 5400
Anthony Firkser TEN TE 8.55 0.62 4600
Green Bay Packers GBP DST 8.04 0.37 4100
9891 148.24 13.37 Jameis Winston NOS QB 33.27 7.44 7000
Dalvin Cook MIN RB 21.82 0.71 10500
Austin Ekeler LAC RB 15.84 0.20 7000
Devontae Booker LVR RB 15.77 1.79 6000
Cooper Kupp LAR WR 14.78 0.52 6600
Brandin Cooks HOU WR 14.91 0.81 6500
Jarvis Landry CLE WR 12.25 0.60 6000
Darren Waller LVR TE 12.43 0.84 7000
New York Giants NYG DST 7.17 0.46 3400
3588 151.01 13.97 Jalen Hurts PHI QB 41.36 7.64 6900
Dalvin Cook MIN RB 22.14 0.71 10500
Austin Ekeler LAC RB 16.22 0.20 7000
Devontae Booker LVR RB 14.50 1.79 6000
Cooper Kupp LAR WR 12.52 0.52 6600
Brandin Cooks HOU WR 13.46 0.81 6500
Jarvis Landry CLE WR 11.42 0.60 6000
Darren Waller LVR TE 11.99 0.84 7000
Atlanta Falcons ATL DST 7.39 0.86 3500
5772 154.09 13.99 Jalen Hurts PHI QB 42.82 7.64 6900
Dalvin Cook MIN RB 23.03 0.71 10500
James Robinson JAC RB 16.98 0.87 7800
Austin Ekeler LAC RB 15.99 0.20 7000
Robert Woods LAR WR 14.38 0.70 7100
Brandin Cooks HOU WR 14.54 0.81 6500
Breshad Perriman NYJ WR 11.88 0.98 5900
Geoff Swaim TEN TE 6.53 1.71 4000
Green Bay Packers GBP DST 7.96 0.37 4100